package com.example.mobile2021606144ywr0509homework;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class SupplierActivity extends AppCompatActivity {

    private TextView tvSupTitle;
    private RadioGroup radBtnSup;
    private RadioButton radSup1;
    private RadioButton radSup2;
    private RadioButton radSup3;
    private RadioButton radSup4;
    private RadioButton radSup5;
    private RadioButton radSup6;
    private RadioButton radSup7;
    private RadioButton radSup8;
    private Button btnSupnext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supplier);
        initView();
        btnSupnext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int radBtnId=radBtnSup.getCheckedRadioButtonId();
                if (radBtnId!=-1){
                    RadioButton radioButton=findViewById(radBtnId);
                    Intent intent=new Intent();
                    intent.putExtra("supplier",radioButton.getText().toString());
                    setResult(RESULT_OK,intent);
                    finish();
                }else{
                    new AlertDialog.Builder(SupplierActivity.this)
                            .setMessage("请选择原材料")
                            .setPositiveButton("确定",null)
                            .create()
                            .show();
                }
            }
        });
    }

    private void initView() {
        tvSupTitle = (TextView) findViewById(R.id.tv_sup_title);
        radBtnSup = (RadioGroup) findViewById(R.id.rad_btn_sup);
        radSup1 = (RadioButton) findViewById(R.id.rad_sup1);
        radSup2 = (RadioButton) findViewById(R.id.rad_sup2);
        radSup3 = (RadioButton) findViewById(R.id.rad_sup3);
        radSup4 = (RadioButton) findViewById(R.id.rad_sup4);
        radSup5 = (RadioButton) findViewById(R.id.rad_sup5);
        radSup6 = (RadioButton) findViewById(R.id.rad_sup6);
        radSup7 = (RadioButton) findViewById(R.id.rad_sup7);
        radSup8 = (RadioButton) findViewById(R.id.rad_sup8);
        btnSupnext = (Button) findViewById(R.id.btn_sup_next);
    }
}